Skip to content

P1B: Refactor (packages/ui/src/theme/v2/avatar.ts): Remove duplicated avatar token definitions - #49

Open
Rashidcmuq wants to merge 2 commits into
CMU-17313Q:mainfrom
Rashidcmuq:refactor-avatar-duplication
Open

P1B: Refactor (packages/ui/src/theme/v2/avatar.ts): Remove duplicated avatar token definitions#49
Rashidcmuq wants to merge 2 commits into
CMU-17313Q:mainfrom
Rashidcmuq:refactor-avatar-duplication

Conversation

@Rashidcmuq

Copy link
Copy Markdown

Issue for this PR

Closes #47

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Qlty reported duplicated code between V2_AVATAR_LIGHT and V2_AVATAR_DARK in packages/ui/src/theme/v2/avatar.ts. I refactored the repeated avatar token structure into a shared helper function while keeping the same light and dark color values. This removes the duplication without changing the output of the avatar theme tokens.

I also added tests for both the light and dark avatar tokens to make sure the refactor keeps the existing values.

How did you verify your code works?

I ran the tests for the UI package and the new avatar tests passed. I also generated a coverage report, which shows src/theme/v2/avatar.ts at 100% function and line coverage.

I reran Qlty on packages/ui/src/theme/v2/avatar.ts after the refactor and the duplicated-code smell is no longer reported.

Commands used:

bun test ./src/theme/v2/avatar.test.ts

bun test

bun test --coverage --coverage-dir=./coverage

qlty smells --no-snippets packages/ui/src/theme/v2/avatar.ts

Screenshots / recordings

Before Qlty:
Before Qlty

After Qlty:
Screenshot 2026-09-03 at 14 16 22

Avatar tests passing:
Avatar tests passing

UI package tests:
UI package tests

Test coverage:
Test coverage

Lint:
Screenshot 2026-09-03 at 14 12 37

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P1B: Refactor (packages/ui/src/theme/v2/avatar.ts): Found 21 lines of similar code in 2 locations (mass = 105)

1 participant